//
//  NgShopCollectionViewCell.m
//  NgTopOSShove
//
//  Created by yscompany on 2018/11/27.
//  Copyright © 2018 NgTopOS. All rights reserved.
//

#import "NgShopCollectionViewCell.h"
#import "Shop.h"
#import "UIImageView+WebCache.h"

@interface NgShopCollectionViewCell ()

@property (nonatomic, strong) UIImageView *shopImgView; //商品图片
@property (nonatomic, strong) UILabel *descShopLab;//商品介绍
@property (nonatomic, strong) UIButton *disCountAmountBtn;//折扣金额
@property (nonatomic, strong) UIButton *dicCountTagBtn;//优惠券标签
@property (nonatomic, strong) UILabel *salesCountLab;//销售数量
@property (nonatomic, strong) UILabel *saleAmountLab;//销售金额
@property (nonatomic, strong) UILabel *earnAmountLab;//省多少钱

@end

@implementation NgShopCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setSubviews];
    }
    return self;
}
- (void)setSubviews {
    self.layer.borderColor = kColorWithRGB(220, 220, 220).CGColor;
    self.layer.borderWidth = 0.5;
    CGFloat cellW = CGRectGetWidth(self.frame);
    CGFloat cellH = CGRectGetHeight(self.frame);
    
    self.shopImgView.frame = CGRectMake(5, 5, cellW - 10, cellH - 120);
    [self addSubview:self.shopImgView];
    
    self.descShopLab.frame = CGRectMake(CGRectGetMinX(self.shopImgView.frame), CGRectGetMaxY(self.shopImgView.frame) + 10, CGRectGetWidth(self.shopImgView.frame), 40);
    [self addSubview:self.descShopLab];
    
    self.disCountAmountBtn.frame = CGRectMake(CGRectGetMinX(self.shopImgView.frame), CGRectGetMaxY(self.descShopLab.frame), 30, 20);
    [self addSubview:self.disCountAmountBtn];
    
    self.dicCountTagBtn.frame = CGRectMake(CGRectGetMaxX(self.disCountAmountBtn.frame), CGRectGetMinY(self.disCountAmountBtn.frame), 50, 20);
    [self addSubview:self.dicCountTagBtn];
    
    self.salesCountLab.frame = CGRectMake(CGRectGetMaxX(self.dicCountTagBtn.frame) + 10, CGRectGetMidY(self.disCountAmountBtn.frame) - 6, cellW - CGRectGetMaxX(self.dicCountTagBtn.frame) - 15, 12);
    [self addSubview:self.salesCountLab];
    
    self.earnAmountLab.frame = CGRectMake(cellW - 65, CGRectGetMaxY(self.dicCountTagBtn.frame) + 20, 60, 20);
    [self addSubview:self.earnAmountLab];
    
    self.saleAmountLab.frame = CGRectMake(CGRectGetMinX(self.shopImgView.frame), CGRectGetMinY(self.earnAmountLab.frame), cellW - CGRectGetMinX(self.shopImgView.frame) - 70, 20);
    [self addSubview:self.saleAmountLab];
                                          
}

- (void)configureShop:(Shop *)shops {
    [self.shopImgView sd_setImageWithURL:[NSURL URLWithString:shops.img] placeholderImage:[UIImage imageNamed:@"tabbar_picture"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        
    }];
    self.descShopLab.text = [HDVerfiyTools getSafeString:shops.desc];
    [self.disCountAmountBtn setTitle:shops.disCountAmout forState:UIControlStateNormal];
    self.salesCountLab.text = [NSString stringWithFormat:@"销售%@",shops.salesCount];
    self.earnAmountLab.text = [NSString stringWithFormat:@"赚%@元",[HDVerfiyTools getSafeString:shops.earnAmount]];
    self.saleAmountLab.text = [HDVerfiyTools getSafeString:shops.price];
}
#pragma mark - getter method
- (UIImageView *)shopImgView {
    if (!_shopImgView) {
        _shopImgView = [UIImageView new];
        _shopImgView.clipsToBounds = YES;
        _shopImgView.contentMode = UIViewContentModeScaleToFill;
    }
    return _shopImgView;
}
- (UILabel *)descShopLab {
    if (!_descShopLab) {
        _descShopLab = [UILabel new];
        _descShopLab.font = [UIFont systemFontOfSize:14];
        _descShopLab.numberOfLines = 2;
        _descShopLab.textColor = [UIColor blackColor];
    }
    return _descShopLab;
}
- (UIButton *)disCountAmountBtn {
    if (!_disCountAmountBtn) {
        _disCountAmountBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _disCountAmountBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [_disCountAmountBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _disCountAmountBtn.backgroundColor = [UIColor yellowColor];
        _disCountAmountBtn.layer.cornerRadius = 5.0f;
        _disCountAmountBtn.layer.borderColor = kColorWithRGB(120, 120, 120).CGColor;
        _disCountAmountBtn.layer.borderWidth = 0.5;
    }
    return _disCountAmountBtn;
}
- (UIButton *)dicCountTagBtn {
    if (!_dicCountTagBtn) {
        _dicCountTagBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_dicCountTagBtn setTitleColor:kColorWithRGB(190, 190, 190) forState:UIControlStateNormal];
        [_dicCountTagBtn setTitle:@"优惠券" forState:UIControlStateNormal];
        _dicCountTagBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        _dicCountTagBtn.layer.cornerRadius = 5.0f;
        _dicCountTagBtn.layer.borderColor = kColorWithRGB(120, 120, 120).CGColor;
        _dicCountTagBtn.layer.borderWidth = 0.5;
    }
    return _dicCountTagBtn;
}
- (UILabel *)salesCountLab {
    if (!_salesCountLab) {
        _salesCountLab = [UILabel new];
        _salesCountLab.font = [UIFont systemFontOfSize:12];
        _salesCountLab.textColor = kColorWithRGB(110, 110, 110);
        _salesCountLab.textAlignment = NSTextAlignmentRight;
    }
    return _salesCountLab;
}
- (UILabel *)saleAmountLab {
    if (!_saleAmountLab) {
        _saleAmountLab = [UILabel new];
        _saleAmountLab.textColor = [UIColor blackColor];
    }
    return _saleAmountLab;
}
- (UILabel *)earnAmountLab {
    if (!_earnAmountLab) {
        _earnAmountLab = [UILabel new];
        _earnAmountLab.font = [UIFont systemFontOfSize:16];
        _earnAmountLab.backgroundColor = kColorWithRGB(250, 190, 190);
        _earnAmountLab.layer.borderWidth = 0.5;
        _earnAmountLab.layer.borderColor = kColorWithRGB(120, 120, 120).CGColor;
        _earnAmountLab.textAlignment = NSTextAlignmentCenter;
    }
    return _earnAmountLab;
}
@end
